#include "paintarea.h"

PaintArea::PaintArea()
{
    resize(800,600);
    setWindowTitle("Paint");
}

void PaintArea::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    p.drawLine(10,10,600,600);
    p.setPen(Qt::red);
    p.drawRect(10,10, 500,500);
    p.drawRoundedRect(30,10, 400,400, 10,30);

    p.setPen(QPen(Qt::black, 5, Qt::SolidLine, Qt::RoundCap ));
    p.setBrush(Qt::yellow);
    p.drawEllipse(50, 150, 400,300);

    //right ellipse
    p.setRenderHint(QPainter::Antialiasing, true);
    p.setPen(QPen(Qt::black, 5, Qt::SolidLine, Qt::RoundCap ));
    p.setBrush(Qt::yellow);
    p.drawEllipse(300, 150, 400,300);

    //linear gradient
    QLinearGradient g(60, 50, 200, 200);
    g.setColorAt(0.2, Qt::white);
    g.setColorAt(0.6, Qt::green);
    g.setColorAt(1.0, Qt::black);
    p.setBrush(QBrush(g));
    p.drawEllipse(50, 50, 200,150);


    //color wheel
    QConicalGradient c(0,0,0);
    c.setColorAt(0.0/360.0, Qt::red);
    c.setColorAt(60.0/360.0, Qt::yellow);
    c.setColorAt(120.0/360.0, Qt::green);
    c.setColorAt(180.0/360.0, Qt::cyan);
    c.setColorAt(240.0/360.0, Qt::blue);
    c.setColorAt(300.0/360.0, Qt::magenta);
    c.setColorAt(360.0/360.0, Qt::red);

    p.setPen(Qt::NoPen);
    p.setBrush(QBrush(c));

    const int r = 150;
    p.translate(r,r);

    p.drawEllipse(QPoint(0,0), r,r);

    //coordinate translate
    p.resetTransform();
    p.fillRect(10,10,50,100,Qt::black);

    p.save();
    p.translate(100,0);
    p.fillRect(10,10,50,100,Qt::black);

    p.restore();
    p.save();
    p.translate(300,0);
    p.rotate(30);
    p.fillRect(10,10,50,100,Qt::black);

    p.resetTransform();
    p.setPen(QPen(Qt::black, 5, Qt::DashDotDotLine, Qt::RoundCap ));
    p.drawLine(100,0,100,500);
    p.drawLine(200,0,200,500);
    p.drawLine(300,0,300,500);

}















